addpath ./stft/
addpath ../lib


disp('Start');
[x,fs,n_bits] = wavread('test.wav');
x = x.';

[junk,T] = size(x);

% Compute STFTs

l_win = 1024;
overlap = l_win/2;

X = cf_stft(x, l_win, overlap);
min(min(X))
max(max(X))
X = abs(X);

C = real(cf_istft(X, l_win, overlap));
wavwrite(C, fs, n_bits, ['part1' 'band']);

disp('NMF');
niter = 500;
R = 2;

[W H] = NMF(X, R, niter);

K = size(W,2);

for i=1:K,
    A = W(:, i) * H(i,:);
    C = (cf_istft(A, l_win, overlap));
    wavwrite(C, fs, n_bits, ['part1' int2str(i)]);
end
    
A = W * H;
C = (cf_istft(A, l_win, overlap));
wavwrite(C, fs, n_bits, ['part-' 'total']);
disp('End');



